package org.example.service.impl;

import org.example.dao.IDistrictDao;
import org.example.entity.DistrictEntity;
import org.example.service.IDistrictService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Coder
 */
@Service
public class DistrictServiceImpl implements IDistrictService {
    private final IDistrictDao districtDao;

    public DistrictServiceImpl(IDistrictDao districtDao) {
        this.districtDao = districtDao;
    }

    @Override
    public String getName(String code) {
        DistrictEntity districtEntity = new DistrictEntity();
        districtEntity.setCode(code);
        return districtDao.selectSelective(districtEntity).get(0).getName();
    }

    @Override
    public List<DistrictEntity> listByParent(String parent) {
        DistrictEntity districtEntity = new DistrictEntity();
        districtEntity.setParent(parent);
        return districtDao.selectSelective(districtEntity);
    }
}
